#include <iostream>
using namespace std;

//翻转字符串2
class Solution {
public:
    string reverseStr(string s, int k) {
        int _k=0;
        string::iterator it1=s.begin();
        string::iterator it2=s.begin();
        while(it1!=s.end())
        {
            if(_k==2*k)
            {
                reverse(it2,it2+k);
                it2+=_k;
                _k=0;
            }
            else
            {
                ++it1;
                ++_k;
            }
        }
        if(_k<k)
        {
            reverse(it2,it2+_k);
        }
        else if(_k<=2*k||_k==k)
        {
            reverse(it2,it2+k);
        }
        return s;
    }
};